<?php
    require "DB.Class.php";
    $con = Connect("debate");
    if(!$con){
        die("Connection failed: ". mysqli_connect_error());
    }else{
        $username = $_POST['username'];
        $password = $_POST['password'];
        $lv = $_POST['lv'];
        $sql = "SELECT * FROM user WHERE number = '".$username."' and password = '".$password."' and status = '".$lv."';";
        $res = mysqli_query($con, $sql);
        $num = mysqli_num_rows($res);
        if($num == 1){
            setcookie("name", $username,null, '/');
            setcookie("lv", $lv, null, '/');
            $url = "../select.php";
            echo "<script>window.location.href='$url'</script>";
        }else{
            echo "<script>alert('登录失败!')</script>";
            $url = "../index.html";
            echo "<script>window.location.href='$url'</script>";
        }
    }
?>